﻿@namespace BootstrapBlazor.Components
@using System.Media
@inherits ComponentBase
@inject MessageService MessageService
@inject IJSWindow JSWindow

@{
    #region 用来渲染上传文件的委托
    void RenderFileViewer(IEnumerable<IHasReadOnlyPreviewFile> files)
    {
        <BootstrapFileViewer Files="files" OnClickEventPreference=" RenderSingleFileEventPreference.Preview" />
    }
    #endregion
}

<div class="bootstrapFormViewerPropertyContainer">
    <div class="bootstrapFormViewerPropertyItem">
        <div class="bootstrapFormViewerPropertyContainer">
            @if (Title is { })
            {
                <div class="bootstrapFormViewerPropertyLabel">@Title</div>
            }
            @if (RecursionInfo is { } recursionInfo)
            {
                @if (RenderRecursion is { })
                {
                    @RenderRecursion(recursionInfo)
                }
                else
                {
                    @BootstrapFormViewerPropertyRecursion.DynamicRender(recursionInfo)
                }
            }
            else
            {
                @switch (Value)
                {
                    case IHasReadOnlyPreviewFile file:
                        RenderFileViewer([file]);
                        break;
                    case IEnumerable<IHasReadOnlyPreviewFile> files:
                        RenderFileViewer(files);
                        break;
                    case var value:
                        <div class="commonContainers">
                            <pre class="bootstrapFormViewerPropertyText">
                            <TextRenderingSimple Value="@FormatValue" />
                            </pre>
                            @if ((Value, RenderPreference) is (string, RenderPreferenceText { ShowCopyText: true }))
                            {
                                <div class="compactCentered">
                                    <Button Text="复制文字" OnClickWithoutRender="CopyText" />
                                </div>
                            }
                        </div>
                        break;
                }
            }
        </div>
        @if (Describe is { } describe)
        {
            <p class="bootstrapFormViewerPropertyDescription">@describe</p>
        }
    </div>
</div>
